package com.qiyi.player.wonder.plugins.share.view.parts
{
   import com.iqiyi.components.videoshare.ShareBtnsBarUI;
   import com.qiyi.player.base.pub.EnumItem;
   import flash.events.MouseEvent;
   import com.iqiyi.components.global.GlobalStage;
   import flash.net.navigateToURL;
   import flash.net.URLRequest;
   import com.qiyi.player.core.model.def.ChannelEnum;
   import com.iqiyi.components.tooltip.ToolTip;
   
   public class ShareBtnsBar extends ShareBtnsBarUI
   {
      
      public function ShareBtnsBar(param1:String, param2:String, param3:String, param4:EnumItem, param5:String) {
         super();
         this._flvTitle = param1;
         this._flvsubtitle = param2;
         this._flvPic = param3;
         this._channel = param4;
         this._albumId = param5;
         this.initListener();
         this.controlUI();
         ToolTip.getInstance().registerComponent(sinaBtn,"新浪微博");
         ToolTip.getInstance().registerComponent(qzoneBtn,"QQ空间");
         ToolTip.getInstance().registerComponent(tencentBtn,"腾讯微博");
         ToolTip.getInstance().registerComponent(renrenBtn,"人人网");
      }
      
      public static const qitanURI:String = "http://t.qiyi.com/share/share.php";
      
      public static const sinaURI:String = "http://v.t.sina.com.cn/share/share.php";
      
      public static const tencentURI:String = "http://v.t.qq.com/share/share.php";
      
      public static const qqURI:String = "http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey";
      
      public static const renrenURI:String = "http://share.renren.com/share/buttonshare";
      
      public static const SHARE_SINA:String = "www.weibo.com";
      
      public static const SHARE_RENREN:String = "share.renren.com";
      
      public static const SHARE_QQ:String = "sns.qzone.qq.com";
      
      public static const SHARE_QITAN:String = "t.qiyi.com";
      
      public static const SHARE_TENCENT:String = "v.t.qq.com";
      
      private var _videoURL:String;
      
      private var _flashURL:String;
      
      private var _isFullShare:Boolean = true;
      
      private var _flvTitle:String;
      
      private var _flvsubtitle:String;
      
      private var _flvPic:String;
      
      private var _channel:EnumItem;
      
      private var _albumId:String;
      
      private function controlUI() : void {
         var _loc1_:* = 10;
         sinaBtn.x = 0;
         qzoneBtn.x = sinaBtn.x + sinaBtn.width + _loc1_;
         tencentBtn.x = qzoneBtn.x + qzoneBtn.width + _loc1_;
         renrenBtn.x = tencentBtn.x + tencentBtn.width + _loc1_;
      }
      
      public function get flashURL() : String {
         return this._flashURL;
      }
      
      public function set flashURL(param1:String) : void {
         this._flashURL = param1;
      }
      
      public function get videoURL() : String {
         return this._videoURL;
      }
      
      public function set videoURL(param1:String) : void {
         this._videoURL = param1;
      }
      
      public function get isFullShare() : Boolean {
         return this._isFullShare;
      }
      
      public function set isFullShare(param1:Boolean) : void {
         this._isFullShare = param1;
      }
      
      private function initListener() : void {
         renrenBtn.addEventListener(MouseEvent.MOUSE_UP,this.renrenShareHandler,false,0,true);
         sinaBtn.addEventListener(MouseEvent.MOUSE_UP,this.sinaShareHandler,false,0,true);
         qzoneBtn.addEventListener(MouseEvent.MOUSE_UP,this.qzoneShareHandler,false,0,true);
         tencentBtn.addEventListener(MouseEvent.MOUSE_UP,this.tencentShareHandler,false,0,true);
      }
      
      private function destroyListener() : void {
         renrenBtn.removeEventListener(MouseEvent.MOUSE_UP,this.renrenShareHandler);
         sinaBtn.removeEventListener(MouseEvent.MOUSE_UP,this.sinaShareHandler);
         qzoneBtn.removeEventListener(MouseEvent.MOUSE_UP,this.qzoneShareHandler);
         tencentBtn.removeEventListener(MouseEvent.MOUSE_UP,this.tencentShareHandler);
      }
      
      public function enableBtns() : void {
         this.initListener();
         renrenBtn.mouseEnabled = true;
         sinaBtn.mouseEnabled = true;
         qzoneBtn.mouseEnabled = true;
         tencentBtn.mouseEnabled = true;
      }
      
      public function disableBtns() : void {
         this.destroyListener();
         renrenBtn.mouseEnabled = false;
         sinaBtn.mouseEnabled = false;
         qzoneBtn.mouseEnabled = false;
         tencentBtn.mouseEnabled = false;
      }
      
      private function sendURL(param1:String) : void {
         GlobalStage.setNormalScreen();
         navigateToURL(new URLRequest(param1),"_blank");
      }
      
      private function getPlatformName() : String {
         return "爱奇艺视频桌面版";
      }
      
      private function sendPingBackEvent(param1:String, param2:Number, param3:Number) : void {
         var _loc4_:VideoShareEvent = new VideoShareEvent(VideoShareEvent.Evt_ShareLink);
         _loc4_.shareType = param1;
         _loc4_.shareStartTime = param2;
         _loc4_.shareEndTime = param3;
         dispatchEvent(_loc4_);
      }
      
      private function sinaShareHandler(param1:MouseEvent) : void {
         var _loc2_:* = "";
         if(GlobalStage.stage != stage)
         {
            _loc2_ = "@";
         }
         var _loc3_:* = "";
         _loc3_ = sinaURI + "?appkey=1925825497&url=" + this.videoURL + this.publicParam() + "&title=" + encodeURIComponent("我在爱奇艺看了《" + this._flvTitle + "》， 非常精彩，分享给大家！") + "&content=utf-8&pic=" + this._flvPic + "&ralateUid=1731986465";
         this.sendURL(_loc3_);
         this.sendPingBackEvent(SHARE_SINA,this.getStartTime(this.videoURL),this.getEndTime(this.videoURL));
      }
      
      private function renrenShareHandler(param1:MouseEvent) : void {
         var _loc2_:* = "";
         if(this._channel == ChannelEnum.ENTERTAINMENT)
         {
            _loc2_ = renrenURI + "?link=" + this.videoURL + this.publicParam() + "&title=" + encodeURIComponent(this._flvTitle + "（分享自 @爱奇艺）");
         }
         else
         {
            _loc2_ = renrenURI + "?link=" + this.videoURL + this.publicParam() + "&title=" + encodeURIComponent(this._flvTitle + "的精彩片段 （分享自 @爱奇艺）");
         }
         this.sendURL(_loc2_);
         this.sendPingBackEvent(SHARE_RENREN,this.getStartTime(this.videoURL),this.getEndTime(this.videoURL));
      }
      
      private function qzoneShareHandler(param1:MouseEvent) : void {
         var _loc2_:String = qqURI + "?url=" + (this.videoURL + this.publicParam()).split("=").join("%3D");
         this.sendURL(_loc2_);
         this.sendPingBackEvent(SHARE_QQ,this.getStartTime(this.videoURL),this.getEndTime(this.videoURL));
      }
      
      private function tencentShareHandler(param1:MouseEvent) : void {
         var _loc2_:* = "";
         if(GlobalStage.stage != stage)
         {
            _loc2_ = "@";
         }
         var _loc3_:String = tencentURI + "?title=" + encodeURIComponent("我在爱奇艺看了《" + this._flvTitle + "》， 非常精彩，分享给大家！") + "&url=" + (this.videoURL + this.publicParam()).split("=").join("%3D");
         this.sendURL(_loc3_);
         this.sendPingBackEvent(SHARE_TENCENT,this.getStartTime(this.videoURL),this.getEndTime(this.videoURL));
      }
      
      private function publicParam() : String {
         return "-src=sharemodclk131212";
      }
      
      private function getStartTime(param1:String) : Number {
         var startIndex:int = 0;
         var sub:String = null;
         var var_34:String = param1;
         try
         {
            startIndex = var_34.indexOf("share_sTime");
            sub = var_34.substr(startIndex);
            return Number(sub.split("-")[0].substr(12));
         }
         catch(error:Error)
         {
         }
         return 0;
      }
      
      private function getEndTime(param1:String) : Number {
         var startIndex:int = 0;
         var sub:String = null;
         var var_34:String = param1;
         try
         {
            startIndex = var_34.indexOf("share_sTime");
            sub = var_34.substr(startIndex);
            return Number(sub.split("-")[1].substr(12));
         }
         catch(error:Error)
         {
         }
         return 0;
      }
      
      public function destory() : void {
         ToolTip.getInstance().unregisterComponent(sinaBtn);
         ToolTip.getInstance().unregisterComponent(qzoneBtn);
         ToolTip.getInstance().unregisterComponent(tencentBtn);
         ToolTip.getInstance().unregisterComponent(renrenBtn);
      }
   }
}
